from selenium import webdriver
from selenium.webdriver import Keys
from selenium.webdriver.common.by import By
import time
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
driver = webdriver.Edge()
driver.get('https://www.jiuxian.com/')
driver.find_element(By.CLASS_NAME,'headerLogin').click()
driver.find_element(By.XPATH,'/html/body/div/form/div/div/div/div/div[1]/div[4]/div/a[1]/i').click()
# iframe处理
driver.switch_to.frame(driver.find_element(By.ID,'ptlogin_iframe'))
driver.find_element(By.ID,'switcher_plogin').click()
time.sleep(2)
driver.back()
driver.back()
# 搜索茅台
a=driver.find_element(By.CSS_SELECTOR,'.search-form')
a.send_keys('茅台')
a.send_keys(Keys.ENTER)
a1=WebDriverWait(driver,20,0.5).until(EC.presence_of_element_located((By.XPATH,'/html/body/div[6]/div/div[2]/div[5]/ul/li[1]/div[2]/div[1]/a/img')))
a1.click()
# 页面切换
driver.switch_to.window(driver.window_handles[-1])
#加入购物车
driver.find_element(By.LINK_TEXT,'加入购物车').click()



time.sleep(10)